import Vue from 'vue'
import VueRouter from 'vue-router'
import main from '../views/main.vue'

Vue.use(VueRouter)

  const routes = [
    {
      path: '/',
      name: 'main',
      component: main,
      children: [
        { // 首页文章列表
          path: '/', component: () => import( '../views/index.vue')
        },
        { // 文章详情
          path: '/article/:id', component: () => import( '../views/article/_id.vue')
        },

        { // 用户个人中心
          path: '/user/:id', component: () => import( '../views/user/_id.vue'),
          children: [
            { // 用户喜欢的文章
              path: '/user/:id', component: () => import( '../views/user/_id/index.vue')
            },
            { // 用户关注的人
              path: '/user/:id/following', component: () => import( '../views/user/_id/following.vue')
            },
            { // 用户的粉丝
              path: '/user/:id/follows', component: () => import( '../views/user/_id/follows.vue')
            },
          ]
        },
        { // 编辑用户个人资料
          path: '/user/settings/profile', component: () => import( '../views/user/settings/profile.vue')
        },
        {
          path: "/admin/tags",component: () => import( '../views/admin/tags.vue')
        }

      ]
    },
    { // 发布文章
      path: '/editor/new', component: () => import( '../views/editor/new.vue')
    },
  ]

const router = new VueRouter({
  routes
})
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
export default router
